import * as Apis from "../../apis/Api";
import {toJS} from "mobx";
import { observable, action } from 'mobx';
import { WeaTableNew } from 'comsMobx';
const { TableStore } = WeaTableNew;

class RiskStore {

    @observable tableStore = new TableStore();
    @observable chartDatas = [];
    @observable modeInfo;

    @action
    componentWillUnmount = ()=>{
        this.chartDatas = [];
        this.tableStore = new TableStore();
    }

    @action
    mathChart = ()=>{
        const storeDatas = this.tableStore.datas;
        storeDatas.map(c=>{
            let datas = [];
            datas.push(c.start_date);
            datas.push(c.possible);
            datas.push(c.clevel);
            
            this.chartDatas.push(datas);
        });

    }

    @action
    getRiskList=(requestParams={})=>{

        Apis.getModeInfo().then(data1 => {
            this.modeInfo = data1.riskTab;
            const params = {...requestParams,...this.modeInfo};
            Apis.getListFromCube(params).then(data => {
            
                this.tableStore.getDatas(data.datas, 1,10,"",this.mathChart);
            });
        });
        
    }
}

export default RiskStore;